#!/bin/sh
# shellcheck shell=dash disable=SC2169

STARTPWD=$(pwd)
ROOT_FS=$(cut -d'"' -f6 ./repositories)/layer.tar

RC=1

if [ -f "${STARTPWD}/${ROOT_FS}" ]; then
  echo -ne "Overriding container files in / ... "
  # shellcheck disable=SC2114
  rm -rf --one-file-system /
  if ! tar -C / --warning=no-timestamp --no-same-owner -xf "${ROOT_FS}"; then
    echo "ERROR: (tar)"
    RC=1
  else
    echo "OK<br>"
    RC=0
  fi
else
  echo "INFO: no rootfs update found, OK<br>"
fi

exit ${RC}
